package com.bishe.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bishe.domain.Festival;
import com.bishe.sevice.IFestivalService;
import com.bishe.controller.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//@CrossOrigin
@RestController
@RequestMapping("/festival")
public class FestivalController {
    @Autowired
    private IFestivalService iFestivalService;

    @GetMapping
    public R getAll(){
        return new R(true,iFestivalService.list());
    }

    @PostMapping
    public R save(@RequestBody Festival festival){
        return new R(iFestivalService.save(festival));
    }

    @PutMapping
    public R update(@RequestBody Festival festival){
        return new R(iFestivalService.modify(festival));
    }

    @DeleteMapping("{id}")
    public R delete(@PathVariable Integer id){
        return new R(iFestivalService.delete(id));
    }

    @GetMapping("{id}")
    public R getById(@PathVariable Integer id) {
        return new R(true, iFestivalService.getById(id));
    }

    @GetMapping("{currentPage}/{pageSize}")
    public R getPage(@PathVariable int currentPage, @PathVariable int pageSize){

        IPage<Festival> page = iFestivalService.getPage(currentPage,pageSize);
        if(currentPage >page.getPages()){
            page = iFestivalService.getPage((int)page.getPages(),pageSize);
        }
        return new R(true,page);
    }

    @GetMapping("/cx/{uid}")
    public R GetBy1(@PathVariable String uid){
        return new R(true,iFestivalService.GetBy(uid));
    }
}
